home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / softwareproperties / gtk / DialogCacheOutdated.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.4 KB  |  63 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import subprocess
  6. import thread
  7. import time
  8. import gobject
  9. import gtk
  10. import gtk.glade as gtk
  11. import apt_pkg
  12.  
  13. class DialogCacheOutdated:
  14.     
  15.     def __init__(self, parent, datadir):
  16.         '''setup up the gtk dialog'''
  17.         self.parent = parent
  18.         if os.path.exists('../data/dialogs.glade'):
  19.             self.gladexml = gtk.glade.XML('../data/dialogs.glade')
  20.         else:
  21.             self.gladexml = gtk.glade.XML('%s/glade/dialogs.glade' % datadir)
  22.         self.dialog = self.gladexml.get_widget('dialog_cache_outofdate')
  23.         self.dialog.set_transient_for(parent)
  24.  
  25.     
  26.     def update_cache(self, window_id, lock):
  27.         '''start synaptic to update the package cache'''
  28.         
  29.         try:
  30.             apt_pkg.PkgSystemUnLock()
  31.         except SystemError:
  32.             pass
  33.  
  34.         cmd = [
  35.             '/usr/sbin/synaptic',
  36.             '--hide-main-window',
  37.             '--non-interactive',
  38.             '--parent-window-id',
  39.             '%s' % window_id,
  40.             '--update-at-startup']
  41.         subprocess.call(cmd)
  42.         lock.release()
  43.  
  44.     
  45.     def run(self):
  46.         '''run the dialog, and if reload was pressed run synaptic'''
  47.         res = self.dialog.run()
  48.         self.dialog.hide()
  49.         if res == gtk.RESPONSE_APPLY:
  50.             self.parent.set_sensitive(False)
  51.             lock = thread.allocate_lock()
  52.             lock.acquire()
  53.             t = thread.start_new_thread(self.update_cache, (self.parent.window.xid, lock))
  54.             while lock.locked():
  55.                 while gtk.events_pending():
  56.                     gtk.main_iteration()
  57.                     time.sleep(0.05)
  58.             self.parent.set_sensitive(True)
  59.         
  60.         return res
  61.  
  62.  
  63.